package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.ypcredit.YpcreditAssessmentData;
import com.ucredit.babel.common.model.third.ypcredit.YpcreditAssessmentRecord;
import com.ucredit.babel.common.model.third.ypcredit.YpcreditAssessmentScore;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 天创天辰分
 *
 * @author szw
 */

public class YpcreditAssessmentParse extends ParseBase {

    private Text val = new Text();
    private Text key = new Text();

    /**
     * 天创天辰分
     *
     * @param model
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {

        YpcreditAssessmentRecord obj = (YpcreditAssessmentRecord) model;
        YpcreditAssessmentData data = obj.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        StringBuilder tcSb = new StringBuilder();

        tcSb.append(data.getStatus()).append(CRT001);
        tcSb.append(data.getMessage() == null ? "" : data.getMessage()).append(CRT001);
        tcSb.append(data.getSeqNum() == null ? "" : data.getSeqNum()).append(CRT001);
        tcSb.append(data.getGid() == null ? "" : data.getGid()).append(CRT001);
        YpcreditAssessmentScore subData = data.getData();
        tcSb.append(subData.getModelScoreZf() == null ? "" : subData.getModelScoreZf()).append(CRT001);
        tcSb.append(subData.getModelScoreZg() == null ? "" : subData.getModelScoreZg()).append(CRT001);
        tcSb.append(subData.getFeeStatus() == null ? "" : subData.getFeeStatus()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + tcSb.toString() + txSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_tc_assessment_credit_inc";
    }

    @Override
    public String getType() {
        return RecordType.YPCREDIT_ASSESSMENT_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "天创天辰分";
    }
}
